package com.ruoyi.carShopService.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.carShopService.domain.CarUserBooking;
import com.ruoyi.carShopService.service.ICarUserBookingService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 维修预约Controller
 * 
 * @author ruoyi
 * @date 2024-09-12
 */
@RestController
@RequestMapping("/booking")
public class CarUserBookingController extends BaseController
{
    @Autowired
    private ICarUserBookingService carUserBookingService;

    /**
     * 查询维修预约列表
     */
    @RequiresPermissions("carShopService:booking:list")
    @GetMapping("/list")
    public TableDataInfo list(CarUserBooking carUserBooking)
    {
        startPage();
        List<CarUserBooking> list = carUserBookingService.selectCarUserBookingList(carUserBooking);
        return getDataTable(list);
    }

    //访问地址: http://localhost:8080/carShopService/booking/list2
//    @RequiresPermissions("carShopService:booking:list2")
    @GetMapping("/list2")
    public TableDataInfo list2(CarUserBooking carUserBooking)
    {
        startPage();
        List<CarUserBooking> list = carUserBookingService.selectCarUserBookingList2(carUserBooking);
        return getDataTable(list);
    }


//访问路径(拼接id和状态): http://localhost:8080/carShopService/booking/updatestaus?bookingId=1&repairStatus="已完成"
    @RequestMapping("/updatestaus")
    public AjaxResult updatestaus(@RequestBody Map<String,String> params)
    {
        CarUserBooking carUserBooking = new CarUserBooking();
        carUserBooking.setRepairOrderNo(params.get("bookingId"));
        carUserBooking.setRepairStatus(params.get("repairStatus"));
        int i = carUserBookingService.updateRepairStatus(carUserBooking);
        if(i>0){
            return AjaxResult.success("修改成功");
        }else{
            return AjaxResult.error("修改失败");
        }
    }


    /**
     * 导出维修预约列表
     */
    @RequiresPermissions("carShopService:booking:export")
    @Log(title = "维修预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarUserBooking carUserBooking)
    {
        List<CarUserBooking> list = carUserBookingService.selectCarUserBookingList(carUserBooking);
        ExcelUtil<CarUserBooking> util = new ExcelUtil<CarUserBooking>(CarUserBooking.class);
        util.exportExcel(response, list, "维修预约数据");
    }

    /**
     * 获取维修预约详细信息
     */
    @RequiresPermissions("carShopService:booking:query")
    @GetMapping(value = "/{bookingId}")
    public AjaxResult getInfo(@PathVariable("bookingId") Long bookingId)
    {
        return success(carUserBookingService.selectCarUserBookingByBookingId(bookingId));
    }

    /**
     * 新增维修预约
     */
    @RequiresPermissions("carShopService:booking:add")
    @Log(title = "维修预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarUserBooking carUserBooking)
    {
        return toAjax(carUserBookingService.insertCarUserBooking(carUserBooking));
    }

    /**
     * 修改维修预约
     */
    @RequiresPermissions("carShopService:booking:edit")
    @Log(title = "维修预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarUserBooking carUserBooking)
    {
        return toAjax(carUserBookingService.updateCarUserBooking(carUserBooking));
    }

    /**
     * 删除维修预约
     */
    @RequiresPermissions("carShopService:booking:remove")
    @Log(title = "维修预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bookingIds}")
    public AjaxResult remove(@PathVariable Long[] bookingIds)
    {
        return toAjax(carUserBookingService.deleteCarUserBookingByBookingIds(bookingIds));
    }
}
